 var id = getvl("id");
 var pifa=0;
 $(function(){
 	if(id!=''&&sessionStorage.getItem("youhuijia")!=''&&sessionStorage.getItem("youhuijia")!=null){
 		 $.ajax({
        url: urlcore + "/api/goods/selectColorAndSizeByGoodsId?goodsId="+id,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					var da=data.data.goods;
					var shangping=
					'<input type="text" style="display: none;" value="'+da.id+'" id="goodsIds">'+
					'<dt>'+
					'<a href="7.0.0goods_detail.html?id='+id+'">'+
'			<img onerror="errorImg(this)" src="'+da.coverUrl+'" />'+
'		</dt>'+
'		<dd>'+
'			<ul class="clearfix">'+
/*'				<li>'+
'					<span>'+da.packNumber+'件</span>'+
'					<h6>&yen;'+(da.packPrice*sessionStorage.getItem("dabaojia"))+'</h6>'+
'                   <input type="text" id="jiage" style="display: none;" value="'+(da.packPrice*sessionStorage.getItem("dabaojia"))+'">'+
'				</li>'+*/
/*'				<li>'+
'					<span></span>'+//'+da.packNumber+'-'+da.tradeNumber+'件
'					<h6></h6>'+ //&yen;'+da.tradePrice+'
'				</li>'+*/

'				<li>'+
'					<span>限时抢购一律</span>'+
'					<h6>&yen;'+sessionStorage.getItem("youhuijia")+'</h6>'+
'                   <input type="text" id="pifajiage" style="display: none;" value="'+sessionStorage.getItem("youhuijia")+'">'+

'				</li>'+
'			</ul>'+
'			<p>'+da.goodsTitle+'</p>'+ //全场满500或15件可混批
'		</dd>';	

                  $("#shangping").append(shangping);
                  $.each(data.data.list, function(y,n) {
                var  goodsguige='<li class="clearfix" id="guige">'+
'			<span>'+n.colour.colourName+'</span>'+
'           <span></span>'+
'			<span>'+n.size.sizeName+'</span>'+
'			<div class="lt-rt">'+
'<input type="text" style="display: none;" id="kuchunid" value="'+n.id+'">'+
'<input type="text" id="shopIds"  style="display: none;" value="'+n.shopId+'">'+
'             <input type="text" style="display: none;" value="'+n.leftNum+'">'+
'             <input type="button" class="minus" onclick="jianhao(this)"  value="-">' +
'             <input type="text" class="zhizhi" id="num" onchange="wenbenkuang(this)" class="result" value="0">' +
'             <input type="button" class="add" onclick="jiahao(this)" value="+">' +
'		    </div>'+
'<input type="text" style="display: none;" id="kuchuanss" value="'+n.leftNum+'">'+
'		    <em>库存'+n.leftNum+'件</em>'+
'		</li>';
                $("#goodsguige").append(goodsguige);
                  });
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});
		
 	}else{
 		alert("超时");
 		window.location.href=history.go(-1);
 	}
 });





function qutianjia(){
          if(uuuuid!=''){
          	if(sessionStorage.getItem("youhuijia")!=""){
          	var jianshu=0;
          	var shu=0;
          	var jine=0;
	     var myStocks =[];
	     var myshook="";
	     var sn=0;
	     myshook+='[';
           $("input[class='zhizhi']").each(function () {
           	 jianshu+=parseInt($(this).val());
           	
           jine=$("#pifajiage").val();
           	    if(parseInt($(this).val())!=0){
           	    	sn++;
                   var pa=parseInt($(this).val());
                   var guige=$(this).prev().prev().prev().prev().val();//规格id
                  //alert(guige)
                   if(sn==1){
                   	 myshook+='{"id":'+guige+',"saleNum":'+pa+',"goodsType":'+3+',"zbDirectSeedingId":'+sessionStorage.getItem("zbid")+',"packRate":'+jine+'}';
                   }else{
                   	 myshook+=',{"id":'+guige+',"saleNum":'+pa+',"goodsType":'+3+',"zbDirectSeedingId":'+sessionStorage.getItem("zbid")+',"packRate":'+jine+'}';
                   }
                /*   alert("***"+pa); //剩余 库存
                   alert("dianpu"+dianpu);
                   alert("guige"+guige);*/

            /* var shoumai=parseInt($(this).val());//售卖件数\
                       myStocks .push({    //后台jihe
                            id: guige,
                            saleNum: pa
                        });*/
           	    }
           });
           myshook+=']';
         if(myshook.length>10){
         if(id!=""){
 	$.ajax({
		url: urlcore + '/api/goodsCar/updateCar2?userId='+uuuuid+"&goodsId="+id,
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
 			"myStocks": myshook,
 		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
			 window.location.href = "11.0.0gouwuche.html";
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	 }
         }else{
         	alert("未选择要购买的商品");
         }
	}else{
		alert("请求超时");
		window.location.href=history.go(-1);
	}
	}else{
	   alert("未登录/或登录超时");
	 
	}
}


function jianhao(ts){
	//alert(ts);
	var t=$(ts).next(); 
    if(t.val()!=''&&t.val()>0){
    	 t.val(parseInt(t.val())-1);
    	 
    }else{
    	 t.val(0);
    }
    zhijin(t.val());
}

function jiahao(ts){
	var t=$(ts).prev();
	var shuju=$(ts).prev().prev().prev();
	//alert(shuju.val());
	if(parseInt(t.val())<parseInt(shuju.val())){
		t.val(parseInt(t.val())+1);
	}else{
		t.val(shuju.val());
	}
	zhijin(t.val());
}

 function wenbenkuang(ts){
   var shu=$(ts);
   	var shuju=$(ts).prev().prev();
   	var results=/^(10|[1-9])$/.test(shu.val());//?"正":"非正";
   	if(parseInt(shu.val())>parseInt(shuju.val())){
   		shu.val(shuju.val());
   	}else if(parseInt(shu.val())<=0 || shu.val()==""){
   		shu.val(0);
   	}else if(results!=false){
       shu.val(1);
   	}
  // alert(shu.val());
  zhijin(shu.val());
}

function zhijin(tva){
	        var zhizhi=0;
	       $("input[class='zhizhi']").each(function () {
	       	zhizhi+=parseInt($(this).val());
            });
	   $("#goodsguigess").html("");
	   $("#hejijiage").html("");
    var jiage=$("#jiage").val();
    var pifajiage=$("#pifajiage").val();
    $("#goodsguigess").html(zhizhi);
     

    	$("#hejijiage").html(parseInt(zhizhi)*pifajiage);
   
    
}
